/**
 * Desenvolvido pela Fábrica de Software do CESUPA.
 * Todos os direitos reservados.
 */
package br.cesupa.fabsoft.nomedoprojeto.system.application.facades.facesmessages;

import java.text.MessageFormat;
import javax.faces.context.FacesContext;

/**
 *
 * @author Breno Leite
 */
public class FacesMessageParameterContext {

    public FacesMessageTranslationContext facesMessageTranslationContext;

    public FacesMessageParameterContext(
            final FacesMessageTranslationContext facesMessageTranslationContext) {
        this.facesMessageTranslationContext = facesMessageTranslationContext;
    }

    /**
     * Uses a set of parameters to construct the message.
     * 
     * @param parameters a set of parameters. May be any kind of object, most
     * commonly primitives or basic objects such {@link String} and {@link Date}.
     */
    public void withParameters(final Object... parameters) {
        facesMessageTranslationContext.getProcessedMessage().setSummary(
                MessageFormat.format(
                facesMessageTranslationContext.getProcessedMessage().getSummary(),
                parameters));
        facesMessageTranslationContext.getProcessedMessage().setDetail(
                MessageFormat.format(
                facesMessageTranslationContext.getProcessedMessage().getDetail(),
                parameters));
        FacesContext.getCurrentInstance().addMessage(
                facesMessageTranslationContext.getFacesMessageFacade().getComponentId(),
                facesMessageTranslationContext.getProcessedMessage());
    }

    public void withoutParameters() {
        FacesContext.getCurrentInstance().addMessage(
                facesMessageTranslationContext.getFacesMessageFacade().getComponentId(),
                facesMessageTranslationContext.getProcessedMessage());
    }
}
